package ink.yql.controller;

import ink.yql.service.AttentionService;
import ink.yql.util.RestObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yql.myutil.MyDate;

@RestController
@RequestMapping("/attention")
public class AttentionController {
    @Autowired
    private AttentionService attentionService;
    @GetMapping("/{sendTime}")
    public RestObject getByUid(@PathVariable("sendTime") Long sendTime){
        // 保护措施  以防拿到url一直请求
        if (System.currentTimeMillis() / 1000 - sendTime > 3) {
            return RestObject.builder().code("400").message("请求时间超时").build();
        }
        return attentionService.getByUid();
    }
    @GetMapping("/{otherid}/{sendTime}")
    public RestObject getByOtherid(@PathVariable("otherid") Integer otherid,@PathVariable("sendTime") Long sendTime){
        // 保护措施  以防拿到url一直请求
        if (new MyDate().getTime()- sendTime > 3) {
            return RestObject.builder().code("400").message("请求时间超时").build();
        }
        return attentionService.getByOtherid(otherid);
    }
    @PostMapping("/{otherid}/{sendTime}")
    public RestObject addOne(@PathVariable("otherid") Integer otherid,@PathVariable("sendTime") Long sendTime){
        // 保护措施  以防拿到url一直请求
        if (System.currentTimeMillis() / 1000 - sendTime > 3) {
            return RestObject.builder().code("400").message("请求时间超时").build();
        }
        return attentionService.addOne(otherid);
    }
}
